package com.lightjet.macross.base.upms.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.lightjet.macross.common.core.BaseEntity;
import com.lightjet.macross.common.core.IntKeyBaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name="UPMS_ROLEINFO")
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler","createDate","updateDate"})
@ApiModel(description = "角色信息实体类")
public class RoleInfo extends IntKeyBaseEntity {
    public RoleInfo(Integer id)
    {
        this.id = id;
    }

    /*@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "SEQGEN_ROLEINFO")
    @SequenceGenerator(name="SEQGEN_ROLEINFO",sequenceName = "ROLEINFO_SEQ")
    @ApiModelProperty(value = "角色ID")
    private Integer id;*/


    //资源所属父节点
    @ManyToOne
    @JoinColumn(name="parentid")
    @JsonBackReference(value="parent-child")
    @ApiModelProperty(value = "角色父节点")
    private RoleInfo parent;

    @ApiModelProperty(value = "角色父节点ID")
    @Column(insertable = false,updatable = false)
    private Integer parentid;

    //资源所属系统
    @ManyToOne
    @JoinColumn(name="systemid")
    @JsonBackReference(value="belongsystem")
    @ApiModelProperty(value = "角色所属系统ID")
    private SystemInfo belongsystem;

    //角色名称
    @ApiModelProperty(value = "角色名称")
    private String rolename;

    //角色编码
    @ApiModelProperty(value = "角色编码")
    private String rolecode;

    //角色描述
    @ApiModelProperty(value = "角色描述")
    private String roledescription;

    //备注信息
    @ApiModelProperty(value = "备注信息")
    private String remark;

    //是否启用 0-禁用 | 1-启用
    @ColumnDefault("1")
    @ApiModelProperty(value = "是否启用 1 启用 | 0 禁用")
    private Integer enabled = 1;

    /** description:子集  */
    @OneToMany(fetch=FetchType.LAZY)
    @JoinColumn(name="parentid")
    @JsonManagedReference("parent-child")
    private List<RoleInfo> children = new ArrayList<>();


}
